package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    /**
     *
     * @param pageNum 当前页码
     * @param pageSize 每页条数
     * @param hospitalQueryVo 查询条件
     * @return 返回提示信息
     */
    @PostMapping ("{pageNum}/{pageSize}")
    public R page(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page = hospitalService.page(pageNum,pageSize,hospitalQueryVo);
        return R.ok().data("total",page.getTotalElements()).data("items",page.getContent());
    }

    //修改医院状态
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    //根据医院id查询医院的详细信息
    @GetMapping("/{id}")
    public R detail(@PathVariable String id){
        Hospital hospital = hospitalService.detail(id);
        //返回给前端
        return R.ok().data("items",hospital);
    }

}
